import request from "@/utils/request";
import { PersonGroupMemberCreateForm } from "./types";
import { AnyAaaaRecord } from "dns";

/**
 * 获取参建单位
 */
export function getProjectCorps(projectId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/getProjectCorps`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/getProjectCorps`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/getProjectCorps`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/getProjectCorps`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/getProjectCorps/` + projectId;
      break;
  }
  return request({
    url: url,
    method: `get`,
  });
}

/**
 * 获取当前项目参建单位所有树结构
 */
export function GetCorpGroupByName(name?: string) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/corp_group_by_name`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/corp_group_by_name`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/corp_group_by_name`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/corp_group_by_name`;
      break;
  }
  return request({
    url: url,
    method: `get`,
    params: { name: name },
  });
}
//获取项目班组列表
export function getProjectGroups(corpId?: number, keywords?: string, projectId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/getProjectGroups`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/getProjectGroups`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/getProjectGroups`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/getProjectGroups`;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/getProjectGroups/` + projectId;
      break;
  }

  return request({
    url: url,
    method: `get`,
    params: { corpId: corpId, keywords: keywords },
  });
}

export function getProjectGroupsByGroupId(groupId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/getProjectGroupsByGroupId`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/getProjectGroupsByGroupId`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/getProjectGroupsByGroupId`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/getProjectGroupsByGroupId`;
      break;
    //   case `Constructor`:
    //     url = `/api/v1/constructor/checkindetail/page_person_month`;
    //     break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    //   case `SysUser`:
    //     url = `/api/v1/sysuser/checkindetail/page_person_month`;
    //     break;
  }

  return request({
    url: url,
    method: `get`,
    params: { groupId: groupId },
  });
}

export function getProjectGroupMembers(groupId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/getProjectGroupMembers`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/getProjectGroupMembers`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/getProjectGroupMembers`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/getProjectGroupMembers`;
      break;
    //   case `Constructor`:
    //     url = `/api/v1/constructor/checkindetail/page_person_month`;
    //     break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    //   case `SysUser`:
    //     url = `/api/v1/sysuser/checkindetail/page_person_month`;
    //     break;
  }

  return request({
    url: url,
    method: `get`,
    params: { groupId: groupId },
  });
}

//分页获取班组人员信息
export function QueryProjectGroupMembers(query: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/page`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/page`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/page`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/page`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/page`;
      break;
  }
  return request({
    url: url,
    method: `get`,
    params: query,
  });
}

export function deleteGroups(groupIds?: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/` + groupIds;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/` + groupIds;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/` + groupIds;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/` + groupIds;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/` + groupIds;
      break;
  }

  return request({
    url: url,
    method: `delete`,
  });
}

export function getGroupForm(groupId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/` + groupId + `/form`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/` + groupId + `/form`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/` + groupId + `/form`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/` + groupId + `/form`;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/` + groupId + `/form`;
      break;
  }

  return request({
    url: url,
    method: `get`,
  });
}

/**
 * 添加
 *
 * @param data
 */
export function addGroup(data: projectGroupForm) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/create`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/create`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/create`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/create`;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/create`;
      break;
  }

  return request({
    url: url,
    method: `post`,
    data: data,
  });
}

/**
 * 更新
 *
 * @param id
 * @param data
 */
export function updateGroup(id: number, data: projectGroupForm) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/` + id;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/` + id;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/` + id;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/` + id;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/` + id;
      break;
  }
  return request({
    url: url,
    method: `put`,
    data: data,
  });
}

/**
 * 一键进场
 *
 */
export function inGroups(ids: string) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/enterArena/` + ids;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/enterArena/` + ids;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/enterArena/` + ids;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/enterArena/` + ids;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/enterArena/` + ids;
      break;
  }
  return request({
    url: url,
    method: `put`,
  });
}

/**
 * 一键离场
 *
 */
export function outGroups(ids: string, endDate: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/appearStage/` + ids;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/appearStage/` + ids;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/appearStage/` + ids;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/appearStage/` + ids;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/appearStage/` + ids;
      break;
  }
  return request({
    url: url,
    method: `put`,
    params: {
      endDate: endDate,
    },
  });
}

/**
 * 班组下拉
 *
 */
export function pullDownGroups(corpId: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/pulldown/` + corpId;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/pulldown/` + corpId;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/pulldown/` + corpId;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/pulldown/` + corpId;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    //   case `SysUser`:
    //     url = `/api/v1/sysuser/checkindetail/page_person_month`;
    //     break;
  }
  return request({
    url: url,
    method: `get`,
  });
}

/**
 * 更换人员所在班组
 *
 * @param data
 */
export function updatePersonMember(data: UpdatePersonMemberformData) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/editPersonGroup`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/editPersonGroup`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/editPersonGroup`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/editPersonGroup`;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    //   case `SysUser`:
    //     url = `/api/v1/sysuser/checkindetail/page_person_month`;
    //     break;
  }
  return request({
    url: url,
    method: `put`,
    data: data,
  });
}

/**
 * 单个人员进场
 *
 * @param data
 */
export function inGroupMember(id: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/inGroupMember/` + id;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/inGroupMember/` + id;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/inGroupMember/` + id;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/inGroupMember/` + id;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    //   case `SysUser`:
    //     url = `/api/v1/sysuser/checkindetail/page_person_month`;
    //     break;
  }
  return request({
    url: url,
    method: `put`,
  });
}

/**
 * 单个人员离场
 *
 * @param data
 */
export function outGroupMember(id: number, endDate: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/outGroupMember/` + id;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/outGroupMember/` + id;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/outGroupMember/` + id;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/outGroupMember/` + id;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    //   case `SysUser`:
    //     url = `/api/v1/sysuser/checkindetail/page_person_month`;
    //     break;
  }
  return request({
    url: url,
    method: `put`,
    params: {
      endDate,
    },
  });
}

/**
 * 导出Excel
 */
export function downloadGroups(projectId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/export`;
      break;
    case `Corp`:
      url = `/api/v1/Corp/projectgroup/export`;
      break;
    case `Constructor`:
      url = `/api/v1/Constructor/projectgroup/export`;
      break;
    case `Commander`:
      url = `/api/v1/Commander/projectgroup/export`;
      break;
    //   case `Commander`:
    //     url = `/api/v1/commander/checkindetail/page_person_month`;
    //     break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/export/` + projectId;
      break;
  }
  return request({
    url,
    method: `get`,
    responseType: `arraybuffer`,
  });
}

/**
 * 获取现场管理人员分页
 */
export function QueryWorkerManagerList(data: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/page_managerEmployees`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/page_managerEmployees`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/page_managerEmployees`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/page_managerEmployees`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/page_managerEmployees`;
      break;
    default:
      url = `/api/v1/manager/useemployee/page_managerEmployees`;
  }
  return request({
    url: url,
    method: `get`,
    params: data,
  });
}

/**
 * 获取用工工人信息分页
 */
export function QueryWorkerList(data: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/page_useEmployees`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/page_useEmployees`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/page_useEmployees`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/page_useEmployees`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/page_useEmployees`;
      break;
    default:
      url = `/api/v1/manager/useemployee/page_useEmployees`;
  }
  return request({
    url: url,
    method: `get`,
    params: data,
  });
}

/**
 * 编辑用工工人
 */
export function EditEmployee(id: number, data: PersonGroupMemberCreateForm) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/editEmployee/` + id;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/editEmployee/` + id;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/editEmployee/` + id;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/editEmployee/` + id;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/editEmployee/` + id;
      break;
    default:
      url = `/api/v1/manager/useemployee/editEmployee/` + id;
  }
  return request({
    url: url,
    method: `post`,
    data: data,
  });
}

/**
 * 注册用工工人
 */
export function RegisterEmployee(data: PersonGroupMemberCreateForm) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/registerEmployee`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/registerEmployee`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/registerEmployee`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/registerEmployee`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/registerEmployee`;
      break;
    default:
      url = `/api/v1/manager/useemployee/registerEmployee`;
  }
  return request({
    url: url,
    method: `post`,
    data: data,
  });
}

/**
 * 判断是否是组长
 */
export function isLeader(groupId: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/isLeader/${groupId}`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/isLeader/${groupId}`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/isLeader/${groupId}`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/isLeader/${groupId}`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/isLeader/${groupId}`;
      break;
    default:
      url = `/api/v1/manager/useemployee/isLeader/${groupId}`;
  }
  return request({
    url: url,
    method: `get`,
  });
}

/**
 * 获取用工工人信息
 */
export function GetEmployeeForm(id: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/member/${id}`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/member/${id}`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/member/${id}`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/member/${id}`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/member/${id}`;
      break;
    default:
      url = `/api/v1/manager/useemployee/member/${id}`;
  }
  return request({
    url: url,
    method: `get`,
  });
}

/**
 * 更换班组长
 */
export function EditMemberLeader(id: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/editMemberLeader/${id}`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/editMemberLeader/${id}`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/editMemberLeader/${id}`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/editMemberLeader/${id}`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/editMemberLeader/${id}`;
      break;
    default:
      url = `/api/v1/manager/useemployee/editMemberLeader/${id}`;
  }
  return request({
    url: url,
    method: `put`,
  });
}

/**
 * 解绑
 */
export function UnbindPerson(id: number) {
  // let url;
  // switch (localStorage.getItem(`usertypeName`)) {
  //   case `Manager`:
  //     url = `/api/v1/manager/useemployee/unbind/${id}`;
  //     break;
  //   case `Corp`:
  //     url = `/api/v1/corp/useemployee/unbind/${id}`;
  //     break;
  //   case `Constructor`:
  //     url = `/api/v1/constructor/useemployee/unbind/${id}`;
  //     break;
  //   case `Commander`:
  //     url = `/api/v1/commander/useemployee/unbind/${id}`;
  //     break;
  //   case `SysUser`:
  //     url = `/api/v1/sysuser/useemployee/unbind/${id}`;
  //     break;
  //   default:
  //     url = `/api/v1/manager/useemployee/unbind/${id}`;
  // }
  // return request({
  //   url: url,
  //   method: `put`,
  // });
}

/**
 * 转入管理组
 */
export function EditTransferManager(row: any) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/useemployee/transferManager/${row.id}`;
      break;
    case `Corp`:
      url = `/api/v1/corp/useemployee/transferManager/${row.id}`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/useemployee/transferManager/${row.id}`;
      break;
    case `Commander`:
      url = `/api/v1/commander/useemployee/transferManager/${row.id}`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/useemployee/transferManager/${row.id}`;
      break;
    default:
      url = `/api/v1/manager/useemployee/transferManager/${row.id}`;
  }
  return request({
    url: url,
    method: `put`,
    data: row,
  });
}
/**
 * 获取项目分页
 */
export function QueryProjectPage(data: any) {
  return request({
    url: `/api/v1/sysuser/project/project_page`,
    method: `get`,
    params: data,
  });
}

/**
 * 获取班组分页
 */
export function QueryProjectGroupPage(projectId: number) {
  return request({
    url: `/api/v1/sysuser/projectgroup/page`,
    method: `get`,
    params: { projectId: projectId, pageNum: 1, pageSize: 9999 },
  });
}

export function GetProjectGroupMemberByGroupId(groupId: number) {
  return request({
    url: `/api/v1/sysuser/projectgroup/getProjectGroupMembers`,
    method: `get`,
    params: { groupId: groupId },
  });
}

/**
 * 下发命令到设备
 */
export function SendDevice(id?: number, type?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/checkindevice/send_person/${id}/${type}`;
      break;
    case `Corp`:
      url = `/api/v1/corp/checkindevice/send_person/${id}/${type}`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/checkindevice/send_person/${id}/${type}`;
      break;
    case `Commander`:
      url = `/api/v1/commander/checkindevice/send_person/${id}/${type}`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/checkindevice/send_person/${id}/${type}`;
      break;
    default:
      url = `/api/v1/manager/checkindevice/send_person/${id}/${type}`;
  }
  return request({
    url: url,
    method: `put`,
  });
}
